/**
 * 外链 script 增加
 * Created by cql on 2017/3/31.
 * */
export default function loadJs ({src, callback = () => {}, onerror = () => {}, charset = 'utf-8'}) {
  let script = document.createElement('script')
  script.type = 'text/javascript'
  script.charset = charset
  script.src = src
  if ('onload' in script) {
    script.onload = callback
    script.onerror = onerror
  } else { // ie 情况
    script.attachEvent('onreadystatechange', function () {
      if (script.readyState === 'complete' || script.readyState === 'loaded') {
        callback()
      }
    })
  }
  (document.head || document.body).appendChild(script)
  return script
}
